package com.richapp.launcher.ui.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.richapp.launcher.R;
import com.richapp.launcher.database.system.mode.RoomModel;

public class ChildRoomLightListAdapter extends BaseAdapter {
	private LayoutInflater layoutInflater = null;
	private List<RoomModel> list = null;
	//现在使用测试数据，后期需要在构造函数上加上ArrayList
	public ChildRoomLightListAdapter(Context context,List<RoomModel> list) {
		this.list = list;
		layoutInflater = LayoutInflater.from(context);
	}
   
	public void setList(List<RoomModel> list){
		this.list = list;
	}
	
	@Override
	public int getCount() {
		if (list == null) {
			return 0;
		}
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = layoutInflater.inflate(R.layout.child_listroomlight_item,
					null);
			viewHolder.roomLightName = (TextView) convertView
					.findViewById(R.id.roomlight_name);
			viewHolder.roomLight = (ImageView) convertView
					.findViewById(R.id.roomlight_light);
			convertView.setTag(viewHolder);
		} else {
            viewHolder = (ViewHolder) convertView.getTag();  
		} 
		RoomModel room = list.get(position);
		viewHolder.roomLightName.setText(room.getRoomName());
		return convertView;
	}

	final class ViewHolder {
		private TextView roomLightName = null;
		private ImageView roomLight = null;
	}
}
